<?php

namespace lib\Server\Mysql;

use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container;

class MysqlOrm
{
	function __construct()
	{
		echo '实例化数据库'.PHP_EOL;

		$capsule = new Capsule;

		$mysqlConfig = \lib\Root::Config('database','mysql');

		$capsule->addConnection([
			'driver' => 'mysql',
			'host' => $mysqlConfig['host'],
			'port' => $mysqlConfig['port'],
			'database' => $mysqlConfig['database'],
			'username' => $mysqlConfig['user'],
			'password' => $mysqlConfig['password'],
			'charset' => $mysqlConfig['charset'],
			'collation' => 'utf8_unicode_ci',
			'prefix' => '',
		]);
		$capsule->setEventDispatcher(new Dispatcher(new Container));
		$capsule->setAsGlobal();
		$capsule->bootEloquent();
	}

}